<?php
	class Db_movie extends CI_Model{
		public function __construct(){
			parent::__construct();
		}
		
		public function movie_all(){
			$config['base_url'] = base_url().'manage_movie/movielist';
			$config['total_rows'] = $this->db->count_all("hotel_movie_category");
			$config['per_page'] = 20;
			$config['full_tag_open'] = '<div class="pages">';
			$config['full_tag_close'] = '<div>';
			$this->pagination->initialize($config);
			$this->db->limit($config['per_page'],$this->uri->segment(3));
			$this->db->order_by("pkid", "desc");
			$res = $this->db->get('hotel_movie_category');
			//==
			$no = $this->uri->segment(3)+1;
			$i = 1;
			$arr = $res->result_array();
			$cat = array();
			foreach ($arr as $P){
				if($i %2 == 0)
					$tmp['back']							="#FFFFFF";
				else
					$tmp['back']							="#F4F4F4";
				$i++;
				$tmp['no']							=$no;
				$tmp['pkid']						=$P['pkid'];
				$tmp['name_en']				=$P['name_en'];
				$tmp['name_zh_cn']			=$P['name_zh_cn'];
				$tmp['name_th']					=$P['name_th'];
				$cat[] = $tmp;
				$no = $no+1;
			}
			$num_row = $config['total_rows'];
			$pagelink  = $this->pagination->create_links();
			return array($cat,$num_row,$pagelink,$config['total_rows']);
		}
		
		public function items_list(){
			$config['base_url'] = base_url().'manage_movie/movie_item_list';
			$config['total_rows'] = $this->db->count_all("hotel_movie");
			$config['per_page'] = 20;
			$config['full_tag_open'] = '<div class="pages">';
			$config['full_tag_close'] = '<div>';
			$this->pagination->initialize($config);
			$this->db->select('t2.pkid,t2.name_en,t1.name_en as cat_name,t2.img,t2.price');
			$this->db->from('hotel_movie_category t1');
			$this->db->join('hotel_movie t2', 't1.pkid = t2.category_pkid');
			$this->db->limit($config['per_page'],$this->uri->segment(3));
			$this->db->order_by("t2.pkid", "desc");
			$res = $this->db->get();
			//==
			$no = $this->uri->segment(3)+1;
			$i = 1;
			$arr = $res->result_array();
			$item = array();
			foreach ($arr as $P){
				if($i %2 == 0)
					$tmp['back']							="#FFFFFF";
				else
					$tmp['back']							="#F4F4F4";
				$i++;
				$tmp['no']							=$no;
				$tmp['pkid']						=$P['pkid'];
				$tmp['title_en']					=$P['name_en'];
				$tmp['name_en']				=$P['cat_name'];
				$tmp['price']						=$P['price'];
				if(trim($P['img']) != "") 
					$tmp['img']	= '<img src="'.base_url().'media/movie/'.$P['img'].'">';
				$item[] = $tmp;
				$no = $no+1;
			}
			$num_row = $config['total_rows'];
			$pagelink  = $this->pagination->create_links();
			return array($item,$num_row,$pagelink,$config['total_rows']);
		}
		
		public function show_cat($group=""){
			$this->db->order_by("pkid","desc");
			$res = $this->db->get('hotel_movie_category');
			$str = '<option value="">=select category=</option>';
			foreach ($res->result_array() as $P){
				if($group == $P['pkid']){
					$check = 'selected="selected"';
				}else{
					$check = "";
				}
				$str .='<option value="'.$P['pkid'].'" '.$check.'>'.$P['name_en'].'</option>';
			}
			return $str;
		}
		
		public function lang_list($id=""){
			$this->db->order_by("pkid","asc");
			$res =$this->db->get("hotel_language");
			$str = '<option value="">=select language=</option>';
			foreach ($res->result_array() as $P){
				if($id == $P['pkid']) $ch = 'selected="selected"';
				else $ch="";
				$str .='<option value="'.$P['pkid'].'" '.$ch.'>'.$P['name'].'</option>';
			}
			return $str;
		}
		
	}
?>